import ResLoader from '../../sysHelper/ResLoader.ts'
import MainComponent from './MainComponent.ts'

class Main extends eui.UILayer {
  constructor() {
    super()
    this.ResLoader = new ResLoader()
    this.mainComponent = new MainComponent()
    this.mainComponent.once('renderOk', function() {
      console.log('renderOk');
      // document.getElementById('manager').dispatchEvent(new Event(renderComplete))
      const renderTexture = new egret.RenderTexture()
      renderTexture.drawToTexture(this)
      console.log('renderTexture', renderTexture)
      window.manager.captureComplete(renderTexture.toDataURL()) 
    }, this)
  }

  createChildren() {
    this.startLoadRes()
  }
  
  startLoadRes() {
    this.resLoader = new ResLoader()
    this.resLoader.addEventListener('majiangComplete', this.startShow, this)
    this.resLoader.startLoading('majiang')
  }

  startShow() {
    console.log('开始展示')
    this.addChild(this.mainComponent)
  }
}

egret.registerClass(Main, 'Main')
window.Main = Main

export default Main